package com.nfit.shopweb.web.api;

import com.github.pagehelper.PageInfo;
import com.nfit.shopmodel.entity.base.ProductUnit;
import com.nfit.shopmodel.vo.common.Result;
import com.nfit.shopmodel.vo.common.ResultCodeEnum;
import com.nfit.shopweb.service.ProductUnitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * ClassName:ProductUnitController
 * Package:com.nfit.shopweb.web.api
 * Description
 *
 * @Author L
 * @Create 2024/12/17 9:01
 */
@RestController
@RequestMapping("/api/productUnit")
public class ProductUnitController {

    @Autowired
    private ProductUnitService productUnitService;

    /**
     * 分页查询
     * @param pageNum 当前页
     * @param pageSize 每页记录数
     */
    @GetMapping("/page/{pageNum}/{pageSize}")
    public Result page(@PathVariable("pageNum") Integer pageNum,
                       @PathVariable("pageSize") Integer pageSize){
      PageInfo<ProductUnit> pageInfo = productUnitService.page(pageNum,pageSize);
      return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(){
      List<ProductUnit> list = productUnitService.selectAll();
      return Result.build(list,ResultCodeEnum.SUCCESS);
    }
}
